Skip to content

feat: de-proxy locale access#3189

Closed
ST-DDT wants to merge 4 commits into
nextfrom
feat/samfn/locale-access
Closed

feat: de-proxy locale access#3189
ST-DDT wants to merge 4 commits into
nextfrom
feat/samfn/locale-access

Conversation

@ST-DDT
Copy link
Copy Markdown
Member

@ST-DDT ST-DDT commented Oct 16, 2024

Second part of the standalone module function feature #2667

Fixes #3155

Requires #2838

Overview

  1. Introduce FakerCore feat: introduce FakerCore #2838
  2. De-proxy locale access feat: de-proxy locale access #3189
  3. De-class config function feat: standalone module functions #3748 (seed, setDefaultRefDate, ...)
  4. De-module functions feat: standalone module functions #3748 (airline, ...)

Description

Instead of calling this.faker.definitions.category.entry, we will now use resolveLocaleData(this.faker.fakerCore, 'category', 'entry').
Please note that this will get simplified with the next PR as this.faker.fakerCore will get replaced with just fakerCore.
This change makes the functions independent from the main faker instance, at least locale access wise.
That makes resolveLocaleData the first effective "standalone module function", as it no longer needs faker, only the fakerCore is needed.

As an additional benefit it also fixes #3155

Recreating the PR

(Partially outdated)

  • Cherry-pick the first two commits.
  • Replace this\.faker\.definitions\.(\w+)\.(\w+) with assertLocaleData(this.faker.fakerCore.locale.$1?.$2, '$1.$2') in src.

Next Steps (Future PR)

The next step after this PR is converting the other methods to standalone module functions.

Current

export class AirlineModule extends ModuleBase {
  airport(): Airport {
    return this.faker.helpers.arrayElement(
      assertLocaleData(this.faker.fakerCore.locale.airline.airport, 'airline', 'airport')
    );
  }
}

Future

function airport(fakerCore: FakerCore): Airport {
  return arrayElement(fakerCore, 
    assertLocaleData(fakerCore.locale.airline.airport, 'airline', 'airport')
  );
}

export class AirlineModule extends ModuleBase {
  airport(): Airport {
    // return airport(this.faker.fakerCore);
    return airport(this.fakerCore);
  }
}

@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent do NOT merge yet Do not merge this PR into the target branch yet labels Oct 16, 2024
@ST-DDT ST-DDT added this to the v10.0 milestone Oct 16, 2024
@ST-DDT ST-DDT self-assigned this Oct 16, 2024
@ST-DDT ST-DDT requested a review from a team as a code owner October 16, 2024 23:58
@ST-DDT ST-DDT marked this pull request as draft October 17, 2024 00:00
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 17, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.90%. Comparing base (c53c1fe) to head (c66ecb9).
⚠️ Report is 1 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3189      +/-   ##
==========================================
- Coverage   98.90%   98.90%   -0.01%     
==========================================
  Files         897      898       +1     
  Lines        3103     3100       -3     
  Branches      556      572      +16     
==========================================
- Hits         3069     3066       -3     
  Misses         30       30              
  Partials        4        4              
Files with missing lines Coverage Δ
src/internal/assert-locale-data.ts 100.00% <100.00%> (ø)
src/internal/locale-proxy.ts 100.00% <100.00%> (ø)
src/modules/airline/index.ts 100.00% <ø> (ø)
src/modules/animal/index.ts 100.00% <100.00%> (ø)
src/modules/book/index.ts 100.00% <100.00%> (ø)
src/modules/color/index.ts 100.00% <100.00%> (ø)
src/modules/commerce/index.ts 98.59% <100.00%> (ø)
src/modules/company/index.ts 100.00% <100.00%> (ø)
src/modules/database/index.ts 100.00% <ø> (ø)
src/modules/date/index.ts 100.00% <100.00%> (ø)
... and 13 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ST-DDT ST-DDT requested a review from a team October 17, 2024 11:12
@ST-DDT ST-DDT marked this pull request as ready for review October 17, 2024 11:12
@ST-DDT ST-DDT linked an issue Oct 18, 2024 that may be closed by this pull request
@ST-DDT ST-DDT marked this pull request as draft November 25, 2024 10:01
@Shinigami92 Shinigami92 modified the milestones: v10.0, v10.x Jul 4, 2025
Base automatically changed from feat/samfn/faker-core to next April 9, 2026 12:50
@ST-DDT
Copy link
Copy Markdown
Member Author

ST-DDT commented Apr 9, 2026

Should I push this PR forward (as a pre-step of #3748) or should I drop it in favor of #3748 (or its parts)?
(Affects all modules that have locale files, could likely be split into one PR per module as well)

TLDR: This PR intends to do:

  • Replace this.faker\.definitions\.(\w+)\.(\w+) and similar
    with assertLocaleData(this.faker.fakerCore.locale.$1.$2, '$1.$2')

#3748 does the same just with this.faker.fakerCore -> fakerCore (during the move to separate files).

@ST-DDT ST-DDT added the s: needs decision Needs team/maintainer decision label Apr 9, 2026
@Shinigami92
Copy link
Copy Markdown
Member

Should I push this PR forward (as a pre-step of #3748) or should I drop it in favor of #3748 (or its parts)? [...]

  • feat: standalone module functions #3748 touches 359 files right now, that are at least 259 files to much for me to make a proper review
    so everything that helps to chunk the PRs down to <100 touched files per PR is a win for reviewers

@matthewmayer
Copy link
Copy Markdown
Contributor

Agreed, if there are ways to chunk the more mechanical changes into seperate PRs like this that make the final PR smaller, and it doesn't break the build, then go for it.

@ST-DDT ST-DDT removed do NOT merge yet Do not merge this PR into the target branch yet s: needs decision Needs team/maintainer decision labels Apr 10, 2026
@ST-DDT ST-DDT force-pushed the feat/samfn/locale-access branch from c67f876 to dc7cd28 Compare April 12, 2026 14:31
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 12, 2026

Deploy Preview for fakerjs ready!

Name Link
🔨 Latest commit c66ecb9
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/69e4f40deef7960008a1bd61
😎 Deploy Preview https://deploy-preview-3189.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ST-DDT ST-DDT force-pushed the feat/samfn/locale-access branch from dc7cd28 to ca3d391 Compare April 12, 2026 15:10
@ST-DDT
Copy link
Copy Markdown
Member Author

ST-DDT commented Apr 12, 2026

I consider splitting this PR into 3 smaller PRs.

  • feat: introduce resolveLocaleData
  • refactor: replace Proxy locale access with resolveLocaleData
  • ?: deprecate LocaleProxy

This PR is theoretically ready for review, but I would like to fix/simplify some code outside of this PR to reduce the diff (complexity).

@ST-DDT
Copy link
Copy Markdown
Member Author

ST-DDT commented Apr 12, 2026

Decision Needed

Which of the three should we do?

  1. const data = resolveLocaleData(core, 'database', 'collation');
    Autocomplete works, but unable to jump directly to the definitions.
  2. const data = assertLocaleData(core.locale.database?.coallation, 'database.coallation');
    Basically a fancy require check. More verbose but also more flexible. Currently internal.
  3. Add both variants, but internally use only one of them.

@ST-DDT ST-DDT added the s: needs decision Needs team/maintainer decision label Apr 12, 2026
This was referenced Apr 12, 2026
Comment thread src/utils/registry.ts Outdated
@xDivisionByZerox
Copy link
Copy Markdown
Member

Decision Needed

Which of the three should we do?

  1. const data = resolveLocaleData(core, 'database', 'collation');
    Autocomplete works, but unable to jump directly to the definitions.
  2. const data = assertLocaleData(core.locale.database?.coallation, 'database.coallation');
    Basically a fancy require check. More verbose but also more flexible. Currently internal.
  3. Add both variants, but internally use only one of them.

Team Decision

We go with option 2 for now. The internal API usage can be verbose, we can use tooling to make our lives easier if required.
The public API for users will be designed in a separate manner.

@xDivisionByZerox xDivisionByZerox removed the s: needs decision Needs team/maintainer decision label Apr 18, 2026
@ST-DDT ST-DDT marked this pull request as draft April 18, 2026 14:19
@ST-DDT ST-DDT force-pushed the feat/samfn/locale-access branch from e201c61 to ae37690 Compare April 18, 2026 15:37
Comment thread src/modules/airline/index.ts
@ST-DDT ST-DDT force-pushed the feat/samfn/locale-access branch from ae37690 to 82eb2f8 Compare April 19, 2026 13:42
@ST-DDT ST-DDT marked this pull request as ready for review April 19, 2026 13:48
@ST-DDT ST-DDT requested review from a team April 19, 2026 13:48
@ST-DDT
Copy link
Copy Markdown
Member Author

ST-DDT commented Apr 19, 2026

Ready for review.

Copy link
Copy Markdown
Member

@xDivisionByZerox xDivisionByZerox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@ST-DDT
Copy link
Copy Markdown
Member Author

ST-DDT commented Apr 19, 2026

I just thought about the following:
If we don't support browsers without Proxy anyway, then we could just use the LocaleProxy in the FakerCore.

  • Then we wouldn't need this PR at all.
  • We would continue to have the short redundancy free calls fakerCore.locale.airline.airport that will still throw.

@ST-DDT ST-DDT added the s: needs decision Needs team/maintainer decision label Apr 19, 2026
@Shinigami92
Copy link
Copy Markdown
Member

Proxy seems fine, go wild

image

@ST-DDT
Copy link
Copy Markdown
Member Author

ST-DDT commented Apr 19, 2026

I created an alternative to this PR:

@xDivisionByZerox xDivisionByZerox dismissed their stale review April 20, 2026 18:14

Withdrawn in favor of #3820

@ST-DDT ST-DDT added wontfix This will not be worked on and removed s: needs decision Needs team/maintainer decision labels Apr 20, 2026
@ST-DDT ST-DDT removed this from the v10.x milestone Apr 20, 2026
@ST-DDT
Copy link
Copy Markdown
Member Author

ST-DDT commented Apr 20, 2026

We will continue to use our LocaleProxy instead of this PR.

See also:

@ST-DDT ST-DDT closed this Apr 20, 2026
@ST-DDT ST-DDT deleted the feat/samfn/locale-access branch April 20, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: feature Request for new feature p: 1-normal Nothing urgent wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support older browsers without Proxy

4 participants